
//= compiler definitions
#define world_matrix          world_matrices[0]
#define world_view_projection world_matrices[1]
//-

//= vertex and pixel structures

struct LaserVertexToPixel
{
    float4 Position     : POSITION;
  
    float3 Normal       : TEXCOORD0;
    float3 Position3D   : TEXCOORD1;
  
    float4 Orig_pos     : TEXCOORD2;
};

struct PixelToFrame
{  
    float4 Color        : COLOR0;
};
//-

//= standard world matrices and light array
uniform extern float4x4 world_matrices[2];
//-

//= Laser bolt variable
uniform extern float4 laser_bolt_color;
uniform extern float draw_lasers;
uniform extern float3 right_light;
uniform extern float3 center_to_viewer;
//-


//-

//++=============================================================================================================================================
// Vertex Shaders 
//++=============================================================================================================================================

LaserVertexToPixel Laser_VertexShader( float4 inPos : POSITION0, float3 inNormal: NORMAL0, float2 inTexCoords : TEXCOORD0, float4 Color : COLOR0)
{
    LaserVertexToPixel Output = (LaserVertexToPixel)0;
   
    Output.Position   = mul(inPos, world_view_projection);
    Output.Normal     = normalize(mul(inNormal, (float3x3) world_matrix));
    Output.Position3D = mul(inPos, world_matrix);
    Output.Orig_pos = inPos;

    return Output;
};

//++=============================================================================================================================================
// Pixel Shaders 
//++=============================================================================================================================================

PixelToFrame Laserbolt_PixelShader (LaserVertexToPixel PSIn)
{
      PixelToFrame Output = (PixelToFrame)0;

      float cosang;
      float DiffuseLightingFactor;
      float4 tc;
    

 // Get the angle.  Since the angle is the shortest route back to the axis, this will
// fix it where it won't care if we're looking at the right or left side.. Center to viewer
//
       cosang = acos(dot(center_to_viewer,PSIn.Normal)); 

// then get the cosine off 90 degrees
       cosang = cos(1.570796327-cosang);

       DiffuseLightingFactor =  pow(cosang,16);
     
       tc =  laser_bolt_color + DiffuseLightingFactor ;
 
      tc.a =  max(pow(cosang,3.5),DiffuseLightingFactor);
  
      Output.Color = tc;
   return Output;
};

//++=============================================================================================================================================
// Techniques 
//++=============================================================================================================================================

technique laserbolt_technique
{
    pass Pass0
    {
         VertexShader = compile vs_2_0 Laser_VertexShader();
         PixelShader = compile ps_2_0 Laserbolt_PixelShader();
    }
}
